<include file="header"/>
<style>
    .grey{
        color: grey;
    }
</style>
<div class="wrapper white-bg">
    <div>
        <img src="/assets/base/eastsoftsurveillance/images/header.jpg" alt="">
    </div>
    <div class="content">
        <form id="frm">
        <div class="list flex">
            <div class="icon iconfont icon-iconfontxingming"></div>
            <input class="input" type="text" id="username" placeholder="请输入姓名">
        </div>
        <div class="list flex">
            <div class="icon iconfont icon-mima"></div>
            <input class="input flex-1" type="text" id="phone" oninput="checkMobile(this)"  placeholder="请输入手机号码">
            <a href="javascript:void(0)" class="blue send show">发送验证码</a>
        </div>
        <div class="list flex">
            <div class="icon iconfont icon-mima"></div>
            <input class="input" type="text" id="code" placeholder="请输入验证码">
        </div>
        </form>
    </div>
    <a href="javascript:void(0)" onclick="sub()" class="btn text-center">注册</a>
</div>
<body>
<script src="/assets/base/eastsoftsurveillance/js/jquery-2.1.0.min.js"></script>
<script>


    // 验证手机号
    function isPhoneNo(phone) {
        var pattern = /^1[34578]\d{9}$/;
        return pattern.test(phone);
    }



    function checkMobile(obj) {
        var c = $('#phone').val();
        if (isPhoneNo($.trim(c)) == false) {
            $('.show').removeClass('blue');
            $('.show').addClass('grey');
        }else{
            $('.show').removeClass('grey');
            $('.show').addClass('blue');
        }
    }




    var height=$(window).height();
    $('.wrapper').css('minHeight',height);


    //点击获取验证码
    var verifyTag = true;
    $('.list').on('click', '.send', function (e) {
        e.preventDefault();
        var phone = $('#phone').val();
        if (isPhoneNo($.trim(phone))== false) {
            fm.alert('手机号格式不正确！');
            return false;
        }else{
            if(verifyTag) {
                timeCountDown(this);
                $.ajax({
                    type: "post",
                    dataType: "json",
                    data: {user_mobile: phone},
                    async: false,
                    url: "/base/eastSoftSurveillance/sendText",
                    success: function (msg) {
                        var msg = JSON.parse(msg);
                        if (msg.status == 'S') {
                            fm.alert(msg.message);
                        } else {
                            fm.alert(msg.message);

                            return false;
                        }

                    }
                });
            }else{
                return 0;
            }
        }
    });
    // 验证倒计时
    function timeCountDown(elem, seconds) {
        verifyTag = false;
        if(typeof seconds == undefined || seconds == null) seconds = 60;
        setTimeout(function () {
            if(seconds > 0) {
                seconds--;
                $(elem).text('已发送 ' + seconds + 's').addClass('time');
                timeCountDown(elem, seconds);
            } else {
                $(elem).removeClass('time').text('获取验证码');
                verifyTag = true;
            }
        }, 1000);
    }

    function sub() {
        var username = $('#username').val();
        var phone = $('#phone').val();
        var code = $('#code').val();

        if (username == '' || phone=='' || code=='') {
                fm.alert('输入内容不能为空');
                return false;
            }else{
                $.ajax({
                    type: "post",
                    dataType: "html",
                    data:$('#frm').serialize(),
                    async:false,
                    url: "/base/eastSoftSurveillance/doRegister/es_vss_id/{BEESCRM:$es_vss_id}",
                    success: function (msg) {
                        var msg = JSON.parse(msg);
                        if(msg.status=='S'){
                           fm.alert(msg.message);
                        }else{
                            fm.alert(msg.message);
                            window.location.reload();
                        }

                    },
                    error:function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            }
        }




</script>
</body>
</html>